<?php

namespace app\admin\model\chase;

use think\Db;
use think\Model;

class ParentStudents extends Model
{
    public static function createOrUpdate($parent_id, $students)
    {
        Db::transaction(function () use($parent_id, $students) {
            self::where('parent_id', $parent_id)->delete();
            $data = [];
            foreach ($students as $val) {
                if ($val) {
                    $data[] = [
                        'parent_id' => $parent_id,
                        'student_id' => $val
                    ];
                }
            }
            self::insertAll($data);
        });
    }
}
